home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-02-06 | 3.0 KB | 179 lines | [TEXT/PJMM] |
- unit Functions;
-
-
- interface
-
- uses
- ParserGlobals;
-
- {following are the functions supported in the parser, besides the usual abs, sqr,sqrt,sin,cos,}
- {exp, ln, round,trunc. log (log to base 10) is also supported.}
-
-
- function asin (var b2: extended): extended;
-
- function acos (var b2: extended): extended;
-
- function tan (var b2: extended): extended;
-
- function atan (var b2: extended): extended;
-
- function sinh (var b2: extended): extended;
-
- function cosh (var b2: extended): extended;
-
- function tanh (var b2: extended): extended;
-
- function inv (var b2: extended): extended;
-
- function invsinh (var b2: extended): extended;
-
- function invcosh (var b2: extended): extended;
-
- function invtanh (var b2: extended): extended;
-
-
-
- implementation
-
- function asin;
-
- label
- 1, 2;
-
- var
- y1, y2, sq, cub: extended;
- n: integer;
-
- begin
- if (b2 = 1) then {Using a Newton-Raphson iteration to 'home in' on the asin function. Starting value}
- begin {determined from the first few terms of series expansion of asin.(done for accuracy)}
- y1 := pi / 2;
- goto 2;
- end;
- if (b2 = -1) then
- begin
- y1 := -pi / 2;
- goto 2;
- end;
- sq := b2 * b2;
- cub := sq * b2;
- y1 := b2 + cub / 6 + (3 * sq * cub) / 40 + (15 * cub * cub * b2) / 336;
- y1 := y1 + (105 * cub * cub * cub) / 3456;
- n := 0;
- 1:
- n := n + 1;
- if n > 25 then
- goto 2;
- y2 := y1 + (b2 - sin(y1)) / cos(y1);
- y1 := y2;
- goto 1;
- 2:
- asin := y1;
- end;
-
-
- function acos;
-
- label
- 1, 2;
-
- var
- y1, y2, sq, cub: extended;
- n: integer;
-
- begin
- if (b2 = 0) then {Using a Newton-Raphson iteration to 'home in' on acos.}
- begin {First estimate determined from first few terms of a}
- y1 := 0; {series expansion of acos. (done for accuracy)}
- goto 2;
- end;
- sq := b2 * b2;
- cub := sq * b2;
- y1 := b2 + cub / 6 + (3 * sq * cub) / 40 + (15 * cub * cub * b2) / 336;
- y1 := y1 + (105 * cub * cub * cub) / 3456;
- y1 := pi / 2 - y1;
- n := 0;
- 1:
- n := n + 1;
- if n > 25 then
- goto 2;
- y2 := y1 - (b2 - cos(y1)) / sin(y1);
- y1 := y2;
- goto 1;
- 2:
- acos := y1;
- end;
-
- function tan;
-
- var
- csn, sgn: extended;
- l: integer;
-
- begin
- csn := cos(b2);
- if csn <= 0 then
- sgn := -1;
- if csn > 0 then
- sgn := 1;
- if abs(csn) <= 1.0e-30 then
- csn := 1.0e-30 * sgn;
- tan := sin(b2) / csn;
- end;
-
- function atan;
-
- begin
- atan := arctan(b2);
- end;
-
- function sinh;
-
- begin
- sinh := 0.5 * (exp(b2) - exp(-b2));
- end;
-
- function cosh;
-
- begin
- cosh := 0.5 * (exp(b2) + exp(-b2));
- end;
-
- function tanh;
-
- begin
- tanh := (exp(2 * b2) - 1) / (exp(2 * b2) + 1);
- end;
-
- function inv;
-
- begin
-
- if b2 <> 0 then
- inv := 1 / b2;
- end;
-
- function invsinh;
-
- begin
- invsinh := ln(b2 + sqrt(b2 * b2 + 1));
- end;
-
- function invcosh;
-
- begin
- if (b2 >= 1) then
- invcosh := ln(b2 + sqrt(b2 * b2 - 1));
- end;
-
- function invtanh;
-
- begin
- if (b2 * b2 >= 0) and (b2 * b2 < 1) then
- invtanh := 0.5 * ln((1 + b2) / (1 - b2));
- end;
-
-
-
- end.